package www.admin.service.impl;

import www.admin.model.UserInfo;

import javax.annotation.Resource;

import www.admin.dao.IUserInfoDao;

import org.springframework.stereotype.Service;

import www.admin.mybatis.Criteria;
import www.admin.service.IUserInfoService;
import www.admin.utils.Layui;
import www.admin.utils.MessageConstant;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;

/**
 * 
 * UserInfo
 * 
 **/

@Service
public class UserInfoServiceImpl implements IUserInfoService{


	public Layui queryPage (Criteria<UserInfo> param){
		PageHelper.startPage(param.getStartIndex(), param.getPageSize());
		List<UserInfo> list = userInfoRepository.queryPage(param);
			PageInfo<UserInfo> paInfo = new PageInfo<UserInfo>(list);
	return Layui.data((int)paInfo.getTotal(), paInfo.getList()); }

	public Integer queryPageCount (Criteria<UserInfo> param){
		return (Integer) userInfoRepository.queryPageCount(param);
	}

	public UserInfo  queryEntity (String userName){
		return userInfoRepository.queryEntity(userName);
	}

	public String deleteById (String id ){
		int result = userInfoRepository.deleteById(id);
			if ( result != 1) {
					return MessageConstant.USER_TYPE_3;
			}
			return null;
	}

	public String insert(UserInfo record ){
		int result = userInfoRepository.insert(record);
			if ( result != 1) { 
					return MessageConstant.USER_TYPE_4;
			}
			return null;
	}

	public String update (Criteria<UserInfo> param){
		int result = userInfoRepository.update(param);
			if ( result != 1) { 
					return MessageConstant.USER_TYPE_5;
			}
			return null;
	}
	
	@Override
	public UserInfo queryByKey(String id) {
		return userInfoRepository.queryByKey(id);
	}
	
	@Override
	public List<String> getUserInfo(String parentResourceId) {
		return userInfoRepository.getUserInfo(parentResourceId);
	}

	@Resource
	private IUserInfoDao userInfoRepository;

}